app.controller("baseController", function ($scope) {
    //分页控件配置
    $scope.paginationConf = {
        currentPage: 1,
        totalItems: 10,
        itemsPerPage: 10,
        perPageOptions: [10, 20, 30, 40, 50],
        onChange: function(){
            $scope.reloadList();//重新加载
        }
    };
    //重新加载列表 数据
    $scope.reloadList = function(){
        //切换页码
        $scope.search( $scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
        $scope.selall = false;
    }

    //品牌id集合
    $scope.selectIds = [];
    //获取选中的id
    $scope.updateSelection = function ($event, id) {
        if ($event.target.checked) {
            $scope.selectIds.push(id);
        }else{
            var index = $scope.selectIds.indexOf(id);
            if(index >= 0) {
                $scope.selectIds.splice(index, 1);
            }
        }
    }
    //全选
    $scope.selectAll = function($event) {
        $scope.list.forEach(function (entity) {
            if(!entity.checked && $event.target.checked) {
                $scope.selectIds.push(entity.id);
            }else if(entity.checked && !$event.target.checked) {
                var index = $scope.selectIds.indexOf(entity.id);
                if(index >= 0) {
                    $scope.selectIds.splice(index, 1);
                }
            }
            entity.checked = $event.target.checked;

        })
    }
    //获取json字符串中的值
    $scope.jsonToString = function (jsonString, key) {
        var json = JSON.parse(jsonString);
        var value = "";
        for(var i = 0; i < json.length; i++) {
            if(i > 0) {
                value += ",";
            }
            value += json[i][key]
        }
        return value;
    }

})